/**
 * @description 七牛云上传相关
 * @author yishen@mdashen.com
 *
 */
const router = require('koa-router')()
const qiniu = require('qiniu')

// 创建上传凭证
const accessKey = 'Zqj8oU29uvYaGDcezLNr4T4UVdITVY0O0L3I6w6o'
const secretKey = 'HooyvUdn44ZmkSdmutN9ED0P4Xgh6EYQFWyxy7tH'
const mac = new qiniu.auth.digest.Mac(accessKey, secretKey)
const options = {
  scope: 'yishen_photos',
  expires: 7200,
}
const putPolicy = new qiniu.rs.PutPolicy(options)
const uploadToken = putPolicy.uploadToken(mac)

router.get('/qiniu/token', async (ctx, next) => {
  ctx.body = {
    error_code: 0,
    msg: '获取成功',
    data: uploadToken,
  }
})

module.exports = router
